package com.hackerrank.challenges.starfleet;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Solution {
	/**
	 * @param v
	 * @param a sorted integer array
	 * @param f search from index
	 * @return index of least element in array a whose value is >= v
	 * length of the array if such element is not found
	 */
	private static int indexOf(int v, Integer a[], int f) {
		int l = f < 0 ? 0 : f, u = a.length - 1;
		while(l <= u) {
			int m = (l + u) / 2;
			if(a[m] < v)
				l = m + 1;
			else if(a[m] > v)
				u = m - 1;
			else
				return m;
		}
		if(f < 0)
			return l;
		return u;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), Q = in.nextInt(), V = in.nextInt();
		TreeMap<Integer, Map<Integer, Integer>> sf = new TreeMap<Integer, Map<Integer, Integer>>();
		for(int i = 0; i < N; i++) {
			int x = in.nextInt(), y = in.nextInt(), f = in.nextInt();
			Map<Integer, Integer> fc = sf.get(y);
			if(fc == null) {
				fc = new HashMap<Integer, Integer>();
				sf.put(y, fc);
			}
			Integer c = fc.get(f);
			fc.put(f, c == null ? 1 : c + 1);
		}
		Set<Integer> ys = sf.keySet();
		Integer y[] = new Integer[ys.size()];
		y = ys.toArray(y);
		Collection<Map<Integer, Integer>> fcc = sf.values();
		Map<Integer, Integer> fc[] = new Map[fcc.size()];
		fc = fcc.toArray(fc);
		for(int i = 1; i < y.length; i++) {
			for(int fcpk : fc[i - 1].keySet()) {
				Integer fcv = fc[i].get(fcpk);
				fc[i].put(fcpk, fc[i - 1].get(fcpk) + (fcv == null ? 0 : fcv));
			}
		}
		for(int i = 0; i < Q; i++) {
			int YU = in.nextInt(), YD = in.nextInt(), T = in.nextInt(), YDi = indexOf(YD, y, -1), YUi = indexOf(YU, y, YDi), M = 0;
			for(int key : fc[YUi].keySet()) {
				int cu = fc[YUi].get(key), cd = 0, c;
				if(YDi > 0) {
					Integer cdi = fc[YDi - 1].get(key);
					cd = cdi == null ? 0 : cdi;
				}
				c = cu - cd;
				if(c > M)
					M = c;
			}
			System.out.println(M);
		}
	}
}
